#!/bin/sh -e

if [ $# -ne 0 ]; then
  echo "warning: this script does not take any argument" >&2
fi

# Check environment variable PLOWSHARE_FORCE_VERSION
# For example: "1.0.1"
if [ -n "$PLOWSHARE_FORCE_VERSION" ]; then
    date=$(date +'%Y-%m-%d')
    echo "v${PLOWSHARE_FORCE_VERSION#v} ($date)"
elif git rev-parse --is-inside-work-tree 1>/dev/null 2>&1; then
    rev=$(git describe --always --tags)
    date=$(git log "$rev" -n1 --pretty=%ci | cut -d' ' -f1)
    echo "$rev ($date)"
else
  echo 'UNKNOWN'
fi
